import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path, { resolve } from 'path'
//图标
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// https://vitejs.dev/config/
export default defineConfig({
  mode:process.env.VITE_MODE,
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
      symbolId: 'icon-[dir]-[name]',
    }),
  ],
  //scss全局变量一个配置
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'scss',
      patterns: [],
    },
  },
  //配置跨域
  server: {

    '/api': {
      target: 'http://jsonplaceholder.typicode.com',
      changeOrigin:true,//解决跨域问题,防止后端host校验
      rewrite: (path) => path.replace(/^\/api/, ''),
    },
    port: 8080, //默认启动端口号
    // open:true ，//自动打开浏览器
    cors: true, //允许跨域
    historyApiFallback: true, //解决路由刷新404问题


  },
  //
  resolve: {
    alias: {
      '@': path.resolve(__dirname,'./src'), // 相对路径别名配置，使用 @ 代替 src
    },
  },
})
